Skip to content

fix(service-cache): report the derived Redis connection into the cluster driver's liveness - #31787

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-v828m0
Nov 9, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-v828m0

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #31723

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 改了什么:共享缓存从 Redis 集群驱动另开的那条连接,现在挂上了错误监听,并接入驱动同一个连接状态(liveness);关闭缓存前先摘监听。
  • 为什么改:Redis 断线时,这条连接每次重连都打印一大段 "Unhandled error event",把唯一有用的那条断线告警淹没了。
  • 风险与回滚:只影响多副本 + Redis 部署的日志与重同步时机;单节点内存缓存不变。回滚即还原本 PR。
  • 先看:packages/services/service-cache/src/cache-service-plugin.ts(接线与关停顺序)、packages/services/service-cluster/src/cluster-resync.ts(watchConnection / watchClusterDriverConnection)、packages/services/service-cluster-redis/src/client.ts(委托)。
  • 两分钟验证:pnpm --filter @objectstack/service-cache exec vitest run src/cache-service-plugin.topology.test.ts,预期 25/25 通过。
  • 需要你做的:无,席位落地。

What changes

  • @objectstack/service-cluster: ClusterDriverLiveness.watchConnection(client, source) is now the one listener style for a driver's connections (error and an unexpected close report down, ready reports up). The client is typed structurally (on/off/status), so the package stays ioredis-free. New export watchClusterDriverConnection(cluster, client, source) resolves the liveness through the module's own private reader and returns a no-op disposer when none is offered.
  • @objectstack/service-cluster-redis: watchRedisConnection delegates to liveness.watchConnection. Its signature and behaviour are unchanged, and its tests are untouched and green.
  • @objectstack/service-cache: the plugin watches only the connection it derives from the driver's (duplicate()), as source 'cache'. One outage now logs one warning across command, subscriber and cache, and cluster.resync waits until the cache's connection is back too. The shutdown hook detaches before cache.close() quits that connection, so a deliberate shutdown is not an outage.
  • No liveness offered (a redis driver released before the liveness offer): the derived connection gets a ClusterDriverLiveness of its own, logging through the plugin's logger. Its outage is logged once, credential-free, in the same text the driver uses. It is not silent, because the card asks for no silent swallow, and it is never once per attempt. Nothing subscribes to that private liveness's resync.
  • Not watched: an injected redis.client (its owner listens), a borrowed client that cannot duplicate(), and the memory cache (no connection).

Tests

New top-level describe in cache-service-plugin.topology.test.ts (the existing harness file):

  1. Real ioredis against a refused port with a password in the URL, over a driver offering a liveness: no [ioredis] Unhandled error event, one warning, no credential, health down/outages: 1, and no plugin-level warning.
  2. The same with no liveness offered: no unhandled event, one warning through the plugin's logger, no credential.
  3. A deliberate shutdown (the quit emits close, as ioredis does) leaves the liveness up with 0 outages and no warning.
  4. cluster.resync waits for the cache's connection: command back gives 0 resyncs, cache back gives exactly 1.
  5. CONTROL: an injected client gets no listener. The existing single-node and memory-driver pins (exact log lines) are unchanged and green.

New describe in cluster-resync.test.ts: watchClusterDriverConnection reports into the offered liveness and its disposer detaches all three listeners. CONTROL: on the memory driver it attaches nothing.

No existing test was edited.

Acceptance notes

  • Besides the seat-accepted watchClusterDriverConnection, the hoist adds one public member, ClusterDriverLiveness.watchConnection. It is the shared inner that watchRedisConnection delegates to (a liveness is already in hand there, pubsub's private one included). This is listed for the seat's ruling.
  • In the no-liveness fallback, the own liveness's warning reuses the driver's text ("Cluster locks, counters and cross-node cache hints fail until it returns…"). That text is accurate for the same store, but it is the driver's wording.

Verification

Head c9c845d2.

RED on main (src of the four production files restored from origin/main c2bb879, rebuilt)

Tests 4 failed | 21 passed (25). Tests 1 and 2 each saw three "[ioredis] Unhandled error event:" lines. Test 3: expected 'unknown' to be 'up' (nothing watched). Test 4: TypeError: liveness.watchConnection is not a function. The ablation A1 below gives this test its behavioural red.

GREEN and package runs

Topology file Tests 25 passed (25). Under the lock, build plus typecheck plus test for service-cluster (145/145, 11 files), service-cluster-redis (41/41, 4 files, the real-redis outage test included) and service-cache (79/79, 5 files): VERDICT command-exit 0. eslint --no-inline-config on the three src dirs: exit 0.

Ablations (scripts/ablation-replace.mjs; each restored, blob == HEAD)
  • A1, cache watches nothing (? (() => {})): 4 failed (tests 1–4).
  • A2, detach after quit (await cache.close(); unwatch();): 1 failed (test 3, the driver's "lost its connection … connection closed" warning appears).
  • A3, own-liveness fallback removed (if (true)): 1 failed (test 2).
  • B1, watchClusterDriverConnection always a no-op: 1 failed (the service-cluster pin).
Gates

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 66 commands on head c9c845d; all 66 ran locally with exit 0. Three first read exit 3 on prerequisites (the teardown self-test's pinned fixture commit, fetched; two gates needing package dists, built with turbo run build --filter='./packages/**', 81/81) and re-ran exit 0. --ran reconciliation: "66 derived famil(ies) accounted for — 66 run, 0 NOT-MEASURED". Families CI runs beyond the derived set are left to the PR's check-runs.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01ADHkmSTGuRMEEW3vjJtdVG

…ter driver's liveness

The shared cache's connection (base.duplicate()) had no error listener, so
every reconnect during a Redis outage printed "[ioredis] Unhandled error
event" with a stack. The listener style the redis driver uses is hoisted
into service-cluster (ClusterDriverLiveness.watchConnection, reached from a
derived connection through watchClusterDriverConnection); the redis
driver's watchRedisConnection delegates to it, and the cache plugin watches
the connection it derives, detaching before its deliberate quit.

Claude-Session: https://claude.ai/code/session_01ADHkmSTGuRMEEW3vjJtdVG
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/service-cache, @objectstack/service-cluster-redis, @objectstack/service-cluster, touching 11 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/services/service-cluster/src/index.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/kernel/contracts/cache-service.mdx (via CacheServicePlugin (symbol, a top-level class))
  • content/docs/kernel/services.mdx (via CacheServicePlugin (symbol, a top-level class))
What this run could not see
  • 1 changed file(s) yielded no anchor (packages/services/service-cluster/src/index.ts) — pages documenting those are invisible to this run
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 231 client-bound route-ledger rows — the other 166 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 166: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 107 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 9 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json e253f3ab09717234fedae8e4d7a193cd1a12b0da → packageMentionDocs.

Which tree this was computed on

This run read content/docs from ad6733450ba518a73383a302a8b1c3f637e4af0e — the merge of head c9c845d29e5d1acf4475a078aadfca1bed8ea176 into base e253f3ab09717234fedae8e4d7a193cd1a12b0da, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin ad6733450ba518a73383a302a8b1c3f637e4af0e && git checkout ad6733450ba518a73383a302a8b1c3f637e4af0e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e253f3ab09717234fedae8e4d7a193cd1a12b0da c9c845d29e5d1acf4475a078aadfca1bed8ea176 && git checkout -B drift-repro e253f3ab09717234fedae8e4d7a193cd1a12b0da && git merge --no-ff c9c845d29e5d1acf4475a078aadfca1bed8ea176

node scripts/docs-audit/affected-docs.mjs --json e253f3ab09717234fedae8e4d7a193cd1a12b0da

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs e253f3ab09717234fedae8e4d7a193cd1a12b0da → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

Contract review

Served-tier: TIER_DEFAULT
Head-sha: c9c845d29e5d1acf4475a078aadfca1bed8ea176
Local-runs: none

① Derived judgments

  • @objectstack/service-cluster gains watchClusterDriverConnection(cluster, client, source): right. It resolves the liveness through the module's own readLiveness, with no Symbol reach-around and no new liveness reader. It returns a no-op disposer when no liveness is offered.
  • ClusterDriverLiveness gains watchConnection(client, source): right. This is the shared inner, taking a structural WatchedConnection (on / off / status), so service-cluster stays ioredis-free.
  • @objectstack/service-cluster-redis's watchRedisConnection: its signature and behavior are unchanged. Its body now delegates to liveness.watchConnection, and its existing tests pass untouched (41/41).
  • @objectstack/service-cache: it adds no export. It watches only the connection it derives from the cluster driver, as 'cache', and detaches before its own quit.

② Semver level

Clause-②: yes (widening) matches: two additive public members and no removal. The patch changesets for the three packages match what the diff publishes.

③ Boundary flags

Both os-dev-report open questions (6731816771) are answered in the seat ACCEPT:

  • watchConnection is accepted as the second public member.
  • The fallback's reuse of the driver's warning text is accepted, because it gives one outage wording.

Implemented-by: claude/project-thread-v828m0
Reviewed-by: session_01ADHkmQKZzp4DLtqiCkZZRM

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

维护者速读

  • 改了什么: 共享缓存从集群驱动派生的那条 Redis 连接现在也挂了错误监听,并接入集群驱动同一个连接状态。监听函数提到 service-cluster 里只保留一份,Redis 驱动和缓存共用。
  • 为什么改: Redis 断线期间,这条连接每次重连都会打印一大段 [ioredis] Unhandled error event,把真正有用的那条告警淹没。现在一次断线在三条连接上只记一次,三条都恢复后才触发 cluster.resync。
  • 风险与回滚: 不新增依赖,内存驱动和进程内缓存不变。缓存主动关闭前先解除监听,正常停机不会被当成断线。回滚即还原本 PR。
  • 先看: packages/services/service-cache/src/cache-service-plugin.ts 的 watchDerivedConnection,以及 service-cluster 的 watchClusterDriverConnection。
  • 需要你做的: 无,由席位落地。
  • 席位意见: ACCEPT。

席位核对 — ACCEPT · domain:server#2 · Head-sha c9c845d29e5d1acf4475a078aadfca1bed8ea176 · 2026-11-09T04:15Z

  1. Shape: draft to main, Fixes #31723, Clause-②: yes (widening), Metadata-protocol: none. Patch changesets for service-cluster, service-cluster-redis and service-cache. 7 files, +368/−18. The surface is as amended on the card (seat ruling A).
  2. Premise: held. RED on main: 4 tests fail, 3 of them on [ioredis] Unhandled error event. GREEN after: 25/25.
  3. Read of the diff:
    • One listener style. ClusterDriverLiveness.watchConnection is the one listener, and both watchRedisConnection and watchClusterDriverConnection delegate to it.
    • What the cache watches. Only its own derived connection, and only when it owns that client and derives it from the cluster driver.
    • No liveness offered. A private liveness on the cache's logger reports an outage once, never silently and never once per reconnect.
    • Shutdown. The cache detaches before its quit(), so a deliberate shutdown is not an outage.
  4. Gates:
    • Dev: 66/66 derived gates ran, with 0 NOT-MEASURED. Three were exit 3 on container prerequisites and cleared. Lint is clean.
    • Tests: cluster 145/145, cluster-redis 41/41, cache 79/79.
    • Ablations: A1–A3 and B1 each red, then restored.
    • Check-runs on this head: 35 success, 15 skipped, 0 failed.
  5. Open questions, ruled:
    • (1) The public member ClusterDriverLiveness.watchConnection is accepted, alongside watchClusterDriverConnection.
    • (2) The fallback reuses the driver's warning text: accepted, one outage wording.
  6. Landing: Clause-② widening with no governed path. The TIER_DEFAULT contract review record on this head is posted beside this ACCEPT. pr_ready + automerge_enable.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 9, 2026 04:16
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 9, 2026 04:16
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit ff8ef4c Nov 9, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-v828m0 branch November 9, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants